package com.zm.service.impl;

import com.zm.dao.AppInfoMapper;
import com.zm.pojo.AppInfo;
import com.zm.service.AppInfoService;
import com.zm.tools.PageDto;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2018/9/13.
 */
@Service
public class AppInfoServiceImpl implements AppInfoService {
    @Resource
    private AppInfoMapper appInfoMapper;
    /**
     * 根据状态信息查询AppInfo信息
     *
     * @param
     * @return
     */
    @Override
    public PageDto selectByStatus(String pagenum,AppInfo appInfo) {
        int pageno=1;
        if (pagenum!=null&&pagenum.matches("\\d")){
            pageno=Integer.parseInt(pagenum);
        }
        int totalcount=appInfoMapper.countpage(appInfo);
        PageDto pageDto=new PageDto<AppInfo>(pageno,totalcount);
        List<AppInfo> list=appInfoMapper.selectByStatus(pageDto);
        pageDto.setList(list);
        return pageDto;
    }

    /**
     * 根据App的ID进行App上架功能
     *
     * @param _id
     * @return
     */
    @Override
    public boolean putaway(String _id) {
        Long id=0l;
        if (_id!=null){
            id=Long.parseLong(_id);
        }
        int i=appInfoMapper.updateBystatus_putaway(id);
        if (i>0){
            return true;
        }
        return false;
    }

    /**
     * 根据App的ID进行App下架功能
     *
     * @param _id
     * @return
     */
    @Override
    public boolean soldout(String _id) {
        Long id=0l;
        if (_id!=null){
            id=Long.parseLong(_id);
        }
        int i=appInfoMapper.updateBystatus_soldout(id);
        if (i>0){
            return true;
        }
        return false;
    }

    /**
     * 根据ID查询App的信息
     *
     * @param _id
     * @return
     */
    @Override
    public AppInfo selectById(String _id) throws Exception {
        Long id=0l;
        if (_id!=null){
            id=Long.parseLong(_id);
        }
        return appInfoMapper.selectByPrimaryKey(id);
    }



    /**
     * 新增App基础信息
     *
     * @param appInfo
     * @return
     */
    @Override
    public boolean addAppinfo(AppInfo appInfo) {
        int i=appInfoMapper.insertSelective(appInfo);
        if (i>0) {
            return true;
        }
        return false;
    }

    /**
     * 审核App
     *
     * @param
     * @param
     * @return
     */
    @Override
    public boolean updateStatus(Long status,Long id) {
        int i=appInfoMapper.updateByStatus(status,id);
        if (i>0){
            return true;
        }

        return false;
    }
}
